package com.lovo.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovo.sys.bean.ProductBean;
import com.lovo.sys.bean.SchemeBean;
import com.lovo.sys.mapper.IProductMapper;
import com.lovo.sys.mapper.ISchemeMapper;
import com.lovo.sys.service.ISchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SchemeServiceImpl implements ISchemeService {
    @Autowired
    private ISchemeMapper schemeMapper;

    @Autowired
    private IProductMapper productMapper;

    @Override
    public IPage<ProductBean> findAllProduct(Integer pageNum) {
        return productMapper.selectPage(new Page<>(pageNum,5),null);
    }

    @Override
    public ProductBean findByProductId(long id) {
        QueryWrapper<ProductBean> qw = new QueryWrapper<>();
        qw.eq("pk_productId",id);
        return productMapper.selectOne(qw);
    }

    @Override
    public List<SchemeBean> findAllScheme() {
        return schemeMapper.selectList(null);
    }

    @Override
    public void addScheme(SchemeBean schemeBean) {
        schemeMapper.insert(schemeBean);
    }

    @Override
    public void updateIdNum(String idNum, int status,String refuse) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("s_idNum",idNum);
        SchemeBean schemeBean = schemeMapper.selectOne(qw);
        schemeBean.setStatus(status);
        schemeBean.setRefuse(refuse);
        schemeMapper.updateById(schemeBean);
    }
}
